import type { PostLoginPasswordData } from '@/types/common'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const userStore = defineStore(
  'user',
  () => {
    const token = ref('')
    const userInfo = ref<PostLoginPasswordData>()
    const setUserInfo = (val: PostLoginPasswordData) => {
      userInfo.value = val
    }
    const ClearUserInfo = () => {
      userInfo.value = undefined
    }
    const setToken = (val: string) => {
      token.value = val
    }
    const clearToken = () => {
      token.value = ''
    }
    return { setToken, clearToken, token, setUserInfo, ClearUserInfo, userInfo }
  },
  {
    persist: true,
  }
)
